package com.example.framework;

import java.io.Serializable;

/**
 * @author : zhayh
 * @date : 2021-6-16 20:10
 * @description : 统一返回类
 */

public class ResponseEntity implements Serializable {
    private boolean isSuccess;
    private int code;
    private String message;
    private Object data;

    private ResponseEntity() {

    }

    public static ResponseEntity success() {
        ResponseEntity result = new ResponseEntity();
        result.setSuccess(true);
        result.setCode(200);
        result.setMessage("请求响应成功");
        return  result;
    }

    public static ResponseEntity success(Object data) {
        ResponseEntity result = success();
        result.setData(data);
        return  result;
    }

    public static ResponseEntity success(Object data, String message) {
        ResponseEntity result = success(data);
        result.setMessage(message);
        return result;
    }

    public static ResponseEntity failure(int code, String message) {
        ResponseEntity result = new ResponseEntity();
        result.setSuccess(true);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static ResponseEntity failure(int code, String message, Object data) {
        ResponseEntity result = failure(code, message);
        result.setData(data);
        return result;
    }

    public boolean isSuccess() {
        return isSuccess;
    }

    public void setSuccess(boolean success) {
        isSuccess = success;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
